#include "processbar.h" 

#include <string.h> 
#include <unistd.h>

const char *lable="|/-\\";
char bar[NUM]={0};


//v2
void processbarCore(int rate)
{
    if(rate <0 || rate >100) return;

    int len=strlen(lable); 
    printf("[%-100s][%d%%][%c]\r",bar,rate,lable[rate%len]);
    fflush(stdout);
    bar[rate++]=BODY;
    if(rate<100)
    {
        bar[rate]=RIGHT;
    }
    else if(rate>100)
    {
        memset(bar,'\0',sizeof(bar));
    }
}

//v1
/*
void processbar(int speed)
{
    int cnt =0;
    while(cnt<=TOP)
    {
        printf("[%-100s][%d%%][%c]\r",bar,cnt,lable[cnt%len]);
        fflush(stdout);
        bar[cnt++]=BODY;
        if(cnt < 100)
        {
            bar[cnt]=RIGHT; 
        }
        usleep(speed);
    }
    printf("\n");
}*/ 
